package com.wuerer.bath.controller;


import com.wuerer.bath.Service.BookService;
import com.wuerer.bath.pojo.Book;
import com.wuerer.bath.pojo.BookForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author admin
 * @version 1.0.0
 * @ClassName BookController.java
 * @Description TODO
 * @createTime 2022年10月16日 10:43
 */
@RestController
@RequestMapping("book")
public class BookController {

    @Autowired
    private BookService bookService;

    @PostMapping("add")
    public String submitBook(@RequestBody BookForm bookForm) {
        boolean b = bookService.addBook(bookForm);
        if (b) {
            return "success";
        } else {
            return "failed";
        }
    }

    @GetMapping("list")
    public List<Book> list() {
        List<Book> list = bookService.list();
        return list;
    }

    @DeleteMapping("delete")
    public boolean deleteBook(@RequestParam("name") String name) {
        return bookService.removeByName(name);
//        return success;
    }
}
